#!/usr/bin/python
# -*- coding:utf-8 -*-
from flask import json
from flask import render_template
from flask import request
from flask_login import login_required, current_user

from app.actions.user import user


@user.route('/edit', methods=['GET', 'POST'])
@login_required
def user_edit():
    edit_user = current_user
    if request.method == 'GET':
        return render_template('user/user_edit.html', edit_user=edit_user)
    else:
        res = {'code': 1000}
        nickname = request.values.get('nickname')
        mail = request.values.get('mail')
        github = request.values.get('github')
        mobile = request.values.get('mobile')
        introduction_one_word = request.values.get('introduction_one_word')
        introduction_detail = request.values.get('introduction_detail')
        if nickname:
            edit_user.nickname = nickname
            edit_user.mail = mail
            edit_user.mobile = mobile
            edit_user.github = github
            edit_user.introduction_one_word = introduction_one_word
            edit_user.introduction_detail = introduction_detail
            edit_user.save()
        else:
            res['code'] = 1001
        return json.dumps(res)


@user.route('/introduction', methods=['GET'])
def user_introduction():
    return render_template('user/user_introduction.html')


@user.route('/experience', methods=['GET'])
def user_experience():
    pass